import java.util.*;

/**
 * @author LKQ
 * @date 2022/2/16 13:34
 * @description
 */
public class FormalSolution {
    public static void main(String[] args) {
        FormalSolution formalSolution = new FormalSolution();
        formalSolution.findLonely(new int[]{10, 6, 5, 8});
    }
    public List<Integer> findLonely(int[] nums) {
        List<Integer> ans = new ArrayList<>();
        if (nums.length == 1) {
            ans.add(nums[0]);
            return ans;
        }
        Arrays.sort(nums);
        for (int i = 0; i < nums.length ; i++) {
            if (i == 0) {
                if (nums[i + 1] - nums[i] > 1) {
                    ans.add(nums[i]);
                }
            }else if ( i == nums.length - 1) {
                if ( nums[i] - nums[i - 1] > 1) {
                    ans.add(nums[i]);
                }
            }else {
                if (nums[i] - nums[i - 1] > 1 && nums[i + 1] - nums[i] > 1) {
                    ans.add(nums[i]);
                }
            }
        }
        return ans;
    }
}
